package net.tatu.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.tatu.base.Page;
import net.tatu.dao.ModelLevelMapper;
import net.tatu.dao.ModelMapper;
import net.tatu.dao.ModelOperateMapper;
import net.tatu.dao.ProjInviteInfoMapper;
import net.tatu.dao.ProjInviteMapper;
import net.tatu.dao.ProjInviteSplitInfoMapper;
import net.tatu.dao.ProjInviteSplitMapper;
import net.tatu.dao.UserMapper;
import net.tatu.model.Model;
import net.tatu.model.ModelLevel;
import net.tatu.model.ModelOperate;
import net.tatu.model.ProjInvite;
import net.tatu.model.ProjInviteInfo;
import net.tatu.model.ProjInviteSplit;
import net.tatu.model.ProjInviteSplitInfo;
import net.tatu.model.User;
import net.tatu.service.ModelService;
import net.tatu.service.ProjInviteService;
import net.tatu.service.UserService;
import net.tatu.util.Encrypt;
import net.tatu.util.Util;

@Service
public class ProjInviteServiceImpl implements ProjInviteService {
	Logger log = Logger.getLogger(ProjInviteServiceImpl.class);
	@Autowired
	ProjInviteMapper projInviteMapper;
	@Autowired
	ProjInviteInfoMapper projInviteInfoMapper;
	@Autowired
	ProjInviteSplitMapper projInviteSplitMapper;
	@Autowired
	ProjInviteSplitInfoMapper projInviteSplitInfoMapper;
	
	@Override
	public String wtTender(ProjInvite projInvite, User u) {
		String ret = "";
		projInvite.setProjInviteId(u.getUserId());
		projInvite.setRecordStatusCode(1);
		ProjInvite pi = projInviteMapper.getProjInviteByProjIdAndProjName(projInvite);
		if(null == pi){
			int i = projInviteMapper.insertProjInvite(projInvite);
			if(i == 1){
				ret = "true";
			}else{
				ret = "insert data failed projInvite:" + projInvite.getProjDesc();
			}
		}else{
			ret = "dumplicated data: projInvite:" + pi.getProjId();
		}
		
		return ret;
	}
	@Override
	public String addTenderFile(ProjInvite projInvite, User u, String url, String fileName) {
		String ret = "";
		ProjInviteInfo projInviteInfo = new ProjInviteInfo();
		projInviteInfo.setRecordStatusCode(1);
		projInvite.setProjInviteId(u.getUserId());
		ProjInvite pi = projInviteMapper.getProjInviteByProjIdAndProjName(projInvite);
		projInviteInfo.setProjId(pi.getProjId());
		projInviteInfo.setInfoUrl(url);
		projInviteInfo.setInfoName(fileName);
		int i = projInviteInfoMapper.insertProjInviteInfo(projInviteInfo);
		if(i == 1){
			ret = "true";
		}
		return ret;
	}
	@Override
	public String zzTender(ProjInviteSplit projInviteSplit, User u) {
		String ret = "";
		projInviteSplit.setProjInviteId(u.getUserId());
		projInviteSplit.setRecordStatusCode(1);
		ProjInviteSplit pis = projInviteSplitMapper.getProjInviteSplitByProjIdAndProjName(projInviteSplit);
		if(null == pis){
			int i = projInviteSplitMapper.insertProjInviteSplit(projInviteSplit);
			if(i == 1){
				ret = "true";
			}else{
				ret = "insert data failed projInvite:" + projInviteSplit.getProjDescSplit();
			}
		}else{
			ret = "dumplicated data: projInvite:" + pis.getProjectSplitId();
		}
		
		return ret;
	}
	@Override
	public String addTenderFile(ProjInviteSplit projInviteSplit, User u, String url, String fileName) {
		String ret = "";
		ProjInviteSplitInfo projInviteSplitInfo = new ProjInviteSplitInfo();
		projInviteSplitInfo.setRecordStatusCode(1);
		projInviteSplit.setProjInviteId(u.getUserId());
		ProjInviteSplit pis = projInviteSplitMapper.getProjInviteSplitByProjIdAndProjName(projInviteSplit);
		projInviteSplitInfo.setProjectSplitId(pis.getProjectSplitId());
		projInviteSplitInfo.setInfoUrl(url);
		projInviteSplitInfo.setInfoName(fileName);
		int i = projInviteSplitInfoMapper.insertProjInviteSplitInfo(projInviteSplitInfo);
		if(i == 1){
			ret = "true";
		}
		return ret;
	}
	
}
